//
//  CTChargeViewController.m
//  CT
//
//  Created by liufanwei on 15/4/6.
//  Copyright (c) 2015年 liufanwei. All rights reserved.
//

#import "CTChargeViewController.h"
#import "CTNetHelper.h"
#import "BDKNotifyHUD.h"
#import "CTUserDefaultHelper.h"
#import "CommonMicro.h"
#import "UILabel+WBExtension.h"

@interface CTChargeViewController ()
@property (weak, nonatomic) IBOutlet UITextField *Number;
@property (weak, nonatomic) IBOutlet UITextField *ChargeNumber;
@property (weak, nonatomic) IBOutlet UITextField *ChargePWD;

@end

@implementation CTChargeViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    NSString * acc = [[CTUserDefaultHelper ShareInstance] Account];
    _Number.text = acc;
    
    UILabel * titleLabel = [UILabel labelWithText:@"官方充值卡充值" font:[UIFont fontWithName:kFontName size:20]];
    titleLabel.textColor = [UIColor whiteColor];
    self.navigationItem.titleView = titleLabel;
    
    _Number.layer.masksToBounds=YES;
    _Number.layer.borderColor= [kRGB(13, 167, 211) CGColor];
    _Number.layer.borderWidth= 2.0f;
    
    _ChargePWD.layer.masksToBounds=YES;
    _ChargePWD.layer.borderColor= [kRGB(13, 167, 211) CGColor];
    _ChargePWD.layer.borderWidth= 2.0f;
    
    _ChargeNumber.layer.masksToBounds=YES;
    _ChargeNumber.layer.borderColor= [kRGB(13, 167, 211) CGColor];
    _ChargeNumber.layer.borderWidth= 2.0f;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}

/*  卡密充值
*  account 账号
*  pin 充值卡号
*  password 充值密码
*/
- (IBAction)onSureClick:(id)sender {
    NSString * chargenumber = _ChargeNumber.text;
    NSString * chargepwd = _ChargePWD.text;
    NSString * acc = _Number.text;
    if (chargenumber == Nil || chargepwd == Nil || acc == Nil ||
        chargenumber.length == 0|| chargepwd.length == 0) {
        [BDKNotifyHUD notifyHUDWithText:@"充值卡卡号或充值卡密码有误"];
        return;
    }
    if (acc.length != 11 || acc.integerValue == 0) {
        [BDKNotifyHUD notifyHUDWithText:@"非法账号"];
        return;
    }
    [[CTNetHelper ShareInstance] charge:@{@"account":acc,@"pin":chargenumber,@"password":chargepwd} WithCallBack:^(id data) {
        if ([[data objectForKey:@"code"] integerValue] == 0) {
            
        }
        [BDKNotifyHUD notifyHUDWithText:[data objectForKey:@"msg"]];
    }];
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
